﻿using System;
using System.Data;

namespace ObjectManager
{
    public class MonHoc : ManagerComponent
    {
        private MonHocDAO MonHocDAO { get; set; }

        public MonHocDTO ThongTin { get; set; }

        private void Initialize()
        {
            MonHocDAO = new MonHocDAO();
            ThongTin = new MonHocDTO();
        }

        public MonHoc()
        {
            Initialize();
        }

        public MonHoc(string Ten)
        {
            Initialize();
            ThongTin.Ten = Ten;
        }

        public MonHoc(string Ten, int SoTinChi)
        {
            Initialize();
            ThongTin.Ten = Ten;
            ThongTin.SoTinChi = SoTinChi;
        }
    
        public override int Add()
        {
            MonHocDAO.MonHocDTO = ThongTin;
            return MonHocDAO.Insert();
        }

        public override int Update()
        {
            MonHocDAO.MonHocDTO = ThongTin;
            return MonHocDAO.Update();
        }

        public override int Remove()
        {
            MonHocDAO.MonHocDTO = ThongTin;
            return MonHocDAO.Delete();
        }

        public DataTable List(int Ma)
        {
            return MonHocDAO.List(Ma);
        }

        public DataTable List(string Ten, string BoMon)
        {
            string ten = "%";
            string bomon = "%";
            if (!string.IsNullOrEmpty(Ten))
            {
                ten = "%" + Ten + "%";
            }
            if (!string.IsNullOrEmpty(BoMon))
            {
                bomon = "%" + BoMon + "%";
            }
            return MonHocDAO.List(ten, bomon);
        }

        public DataTable ListAll()
        {
            return MonHocDAO.ListAll();
        }

        public DataTable ListName()
        {
            return MonHocDAO.ListName();
        }

        public string[] FindName()
        {
            MonHocDAO.MonHocDTO = ThongTin;
            return MonHocDAO.FindName();
        }

        public int MaTiep()
        {
            return MonHocDAO.MaTiep();
        }

        public void Info(string Ma)
        {
            int ma = 0;
            if (!string.IsNullOrEmpty(Ma))
            {
                ma = int.Parse(Ma);
            }
            MonHocDAO.Search(ma);
            this.ThongTin = MonHocDAO.MonHocDTO;
        }
    }
}
